package com.lovegu.hash_tab.impl;

import com.lovegu.hash_tab.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <p>
 * 不完美哈希表实现
 * </p>
 *
 * @author 老顾
 * @since 2023/3/20
 */
public class HashMap01<K, V> implements Map {

    private final Logger logger = LoggerFactory.getLogger(HashMap01.class);

    private final Object[] tab = new Object[8];

    @Override
    public void put(Object key, Object value) {
        int idx = key.hashCode() & (tab.length - 1);
        tab[idx] = value;
    }

    @Override
    public V get(Object key) {
        int idx = key.hashCode() & (tab.length - 1);
        return (V)tab[idx];
    }
}
